package com.ruoyi.costBatchDetail.service.impl;

import com.ruoyi.cost.domain.FundCostT;
import com.ruoyi.costBatchDetail.domain.HouseBatchDetailT;
import com.ruoyi.cost.mapper.HouseCostTMapper;
import com.ruoyi.costBatch.mapper.HouseBatchTMapper;
import com.ruoyi.costBatchDetail.mapper.HouseBatchDetailTMapper;
import com.ruoyi.costBatchDetail.service.IHouseBatchDetailTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 户管理Service业务层处理
 * 
 * @author lijie
 * @date 2023-04-20
 */
@Service
public class HouseBatchDetailTServiceImpl implements IHouseBatchDetailTService
{
    @Autowired
    private HouseBatchDetailTMapper houseBatchDetailTMapper;

    @Autowired
    private HouseCostTMapper houseCostTMapper;

    @Autowired
    private HouseBatchTMapper houseBatchTMapper;

    /**
     * 查询户管理
     * 
     * @param doorId 户管理主键
     * @return 户管理
     */
    @Override
    public List<HouseBatchDetailT> selectBatchDetailTByBatchId(Long doorId)
    {
        return houseBatchDetailTMapper.selectBatchDetailTByBatchId(doorId);
    }

    @Override
    public List<HouseBatchDetailT> selectBatchTByBatchId(Long doorId)
    {
        return houseBatchDetailTMapper.selectBatchTByBatchId(doorId);
    }

    /**
     * 查询户管理列表
     * 
     * @param houseBatchDetailT 户管理
     * @return 户管理
     */
    @Override
    public List<HouseBatchDetailT> selectBatchDetailTList(HouseBatchDetailT houseBatchDetailT)
    {
        return houseBatchDetailTMapper.selectBatchDetailTList(houseBatchDetailT);
    }

    /**
     * 批量添加缴费管理
     *
     * @param houseDoorT 户管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertBatchDetail(FundCostT fundCostT, String[] houseIds, Long batchId)
    {
        int result = 0;
        for(String houseId : houseIds){
            FundCostT doorTempVO = new FundCostT();
            HouseBatchDetailT houseBatchDetailT = new HouseBatchDetailT();
            doorTempVO = houseCostTMapper.selectFundCostTByHouseId(houseId);
            houseBatchDetailT.setCostMoney(doorTempVO.getCostMoney());
            houseBatchDetailT.setBatchId(String.valueOf(batchId));
            houseBatchDetailT.setHouseId(houseId);
            result = houseBatchDetailTMapper.insertBatchDetailT(houseBatchDetailT);
        }
        return result;
    }

    @Transactional
    @Override
    public int deleteBatchDetail(String[] houseIds, Long batchId)
    {
        int result = 0;
        for(String houseId : houseIds){
            HouseBatchDetailT houseBatchDetailT = new HouseBatchDetailT();
            houseBatchDetailT.setBatchId(String.valueOf(batchId));
            houseBatchDetailT.setHouseId(houseId);
            result = houseBatchDetailTMapper.deleteBatchDetailT(houseBatchDetailT);
        }
        return result;
    }
}
